import { createRouter, createWebHashHistory } from 'vue-router'

// 导入公共布局组件(一级路由)
const Layout = () => import('@/views/Layout')
// 导入首页
const Home = () => import('@/views/Home')
// 导入商品详情页面
const GoodDetail = () => import('@/views/good')
// 导入登录页面
const Login = () => import('@/views/login/index')
// 导入购物车页面
const Cart = () => import('@/views/Cart')
// 导入下单页面
const Settlement = () => import('@/views/Member/order/index.vue')
// 导入支付页面
const Pay = () => import('@/views/Member/pay/index')
const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      // 首页
      {
        path: '',
        component: Home
      },
      // 商品详情页
      {
        path: '/detail/:id',
        component: GoodDetail
      },
      // 购物车
      {
        path: '/cart',
        component: Cart
      },
      // 下单
      {
        path: '/order',
        component: Settlement
      },
      // 支付
      { path: '/pay', component: Pay }
    ]
  },
  { path: '/login', component: Login }

]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 路由跳转页面重置滚动
  scrollBehavior() {
    // vue2
    // return { x: 0, y: 0 }
    return { left: 0, top: 0 }
  }
})

export default router
